package py.edu.ucsa.sisalews.config;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

public class SisalewsContextListener implements ServletContextListener {

	Logger log = LoggerFactory.getLogger(getClass());
	static String buildNumber = "unknown";
	static String vendor = "unknown";
	static String version = "unknown";
	static String artifactName = "unknown";
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		org.apache.ibatis.logging.LogFactory.useSlf4jLogging();
		ApplicationContext ctx = SisalewsApplicationContextProvider.getContext();
		
		ApplicationInfo info = (ApplicationInfo) ctx.getBean("applicationInfo");
		
		log.debug("{}", info);
		buildNumber = info.getBuild();
		vendor = info.getVendor();
		artifactName = info.getArtifact();
		version = info.getVersion();
	}

}
